package org.nf.vrs.authenticateservice.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.nf.vrs.authenticate.exception.AuthenticateException;
import org.nf.vrs.authenticate.inf.UserAuthService;
import org.nf.vrs.userservice.dto.UserDTO;
import org.nf.vrs.userservice.inf.UserService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author duang
 * @date 2022/3/30
 */
@Slf4j
/**
 * @DubboService
 */
@DubboService(interfaceClass = UserAuthService.class, version = "1.0.0")
public class UserPasswordAuthServiceImpl implements UserAuthService {
    /**
     *
     * check：启动前 检查zookeeper中有没有可用的服务
      */
    @DubboReference(interfaceClass = UserService.class, version = "1.0.0")
    private UserService service;

    @Override
    public <T> T authenticate(String account, String password) {
        UserDTO userDTO = service.getUserByTel(account);

        if (userDTO==null || !userDTO.getUserPassword().equals(password)) {
            throw new AuthenticateException("账号或密码错误");
        }

        return (T) userDTO;
    }
}